﻿@using System.Text.RegularExpressions
@model Actya.Core.Widgets.TwitterWidget

<h3>@Model.Title</h3>
@if (Model.Tweets != null)
{
	<ul>
		@foreach (var tweet in Model.Tweets)
		{
			<li>
				@Html.Raw(ConvertUrlsToLinks(@tweet.Message))
				<div class="sub"><a href="http://twitter.com/@tweet.User/status/@tweet.Id">@tweet.Timestamp.ToString() by @tweet.User</a></div>
			</li>
		}
	</ul>
}

@functions 
{
	string ConvertUrlsToLinks(string msg) 
	{
		const string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
		var r = new Regex(regex, RegexOptions.IgnoreCase);
		return r.Replace(msg, "<a href=\"$1\">$1</a>").Replace("href=\"www", "href=\"http://www");
	}
}	